package com.suneast.suneaststore.modules.search;

import android.support.v7.util.DiffUtil;

import com.suneast.suneaststore.bean.search.SearchFilterBean;

import java.util.ArrayList;

public class FilterItemDiffUtil extends DiffUtil.Callback {

    private ArrayList<SearchFilterBean> oldList, newList;

    public FilterItemDiffUtil(ArrayList<SearchFilterBean> oldList, ArrayList<SearchFilterBean> newList) {
        this.oldList = oldList;
        this.newList = newList;
    }

    @Override
    public int getOldListSize() {
        return oldList == null ? 0 : oldList.size();
    }

    @Override
    public int getNewListSize() {
        return newList == null ? 0 : newList.size();
    }

    @Override
    public boolean areItemsTheSame(int oldItemPosition, int newItemPosition) {
        return oldList.get(oldItemPosition).getTitle()
                .equals(newList.get(newItemPosition).getTitle());
    }

    @Override
    public boolean areContentsTheSame(int oldItemPosition, int newItemPosition) {
        return oldList.get(oldItemPosition).getItemList().size()
                == newList.get(newItemPosition).getItemList().size();
    }
}
